import { request, config } from 'utils'

const { api } = config
const { customerEmployerAddressEdit, customerEmployerAddressDel, customerEmployerAddressQuery, customerEmployerPhoneEdit, customerEmployerPhoneDel, customerEmployerPhoneQuery } = api
const { accoutSignEmployerAddressEdit, accoutSignEmployerAddressDel, accoutSignEmployerAddressQuery, accoutSignEmployerPhoneEdit, accoutSignEmployerPhoneDel, accoutSignEmployerPhoneQuery } = api

function apiSelect (type) {
  let EmployerApi = {}
  switch (type) {
    case 'customerEmployer':
      EmployerApi.addressEditAPI = customerEmployerAddressEdit
      EmployerApi.addressDelAPI = customerEmployerAddressDel
      EmployerApi.addressQueryAPI = customerEmployerAddressQuery
      EmployerApi.phoneEditAPI = customerEmployerPhoneEdit
      EmployerApi.phoneDelAPI = customerEmployerPhoneDel
      EmployerApi.phoneQueryAPI = customerEmployerPhoneQuery
      break
    case 'signEmployer':
      EmployerApi.addressEditAPI = accoutSignEmployerAddressEdit
      EmployerApi.addressDelAPI = accoutSignEmployerAddressDel
      EmployerApi.addressQueryAPI = accoutSignEmployerAddressQuery
      EmployerApi.phoneEditAPI = accoutSignEmployerPhoneEdit
      EmployerApi.phoneDelAPI = accoutSignEmployerPhoneDel
      EmployerApi.phoneQueryAPI = accoutSignEmployerPhoneQuery
      break
    default:
  }
  return EmployerApi
}

export async function addressQuery (params) {
  const { addressQueryAPI } = apiSelect(params.type)

  return request({
    url: addressQueryAPI,
    method: 'put',
    data: params,
  })
}

export async function phoneQuery (params) {
  const { phoneQueryAPI } = apiSelect(params.type)

  return request({
    url: phoneQueryAPI,
    method: 'put',
    data: params,
  })
}

export async function addressEdit (params) {
  const { addressEditAPI } = apiSelect(params.type)

  return request({
    url: addressEditAPI,
    method: 'put',
    data: params,
  })
}

export async function addressDel (params) {
  const { addressDelAPI } = apiSelect(params.type)
  return request({
    url: addressDelAPI,
    method: 'delete',
    data: params,
  })
}

export async function phoneEdit (params) {
  const { phoneEditAPI } = apiSelect(params.type)
  return request({
    url: phoneEditAPI,
    method: 'put',
    data: params,
  })
}

export async function phoneDel (params) {
  const { phoneDelAPI } = apiSelect(params.type)
  return request({
    url: phoneDelAPI,
    method: 'delete',
    data: params,
  })
}

